<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" type="text/css" href="css/public.css"/>
    <link rel="stylesheet" type="text/css" href="css/login.css"/>
</head>
<body><!-------------------login-------------------------->
<div class="login">
    <form onsubmit="return false" ><h1><a href="/"><img src="img/temp/logo.png"></a></h1>
        <p></p>
        <div class="msg-warn hide"><b></b>公共场所不建议自动登录，以防账号丢失</div>
        <p><input type="text" id="username" value="" placeholder="用户名" required></p>
        <p><input type="password" style="border: 1px solid #dbdbdb" id="password"  value="" placeholder="密码" required></p>
        <p><input type="submit" name="" onclick="login(this.id)" th:id="${url}" value="登  录"></p>
        <p class="txt"><a class="" href="/reg">免费注册</a></p>
    </form>
</div>
</body>
<script src="js/jquery-1.12.4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/sweetalert.js"> </script>

<script>


    function login(url) {
        var password = $("#password").val();
        var username = $("#username").val();
        if (password.length<=0  || username.length<=0){
            return;
        }
        $.post("user/login",{password,username},function (result) {
            if (result.state=='error'){
                swal("OMG!", result.msg+"！！", "error")
            }else{
                if(url.length>0){
                    window.location.replace(url)
                }
                window.location.replace("/")

            }

        })

    }

</script>
</html>